package com.epam.player.vkapi.authentication;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.jsoup.Connection;

import com.epam.player.vkapi.ApllicationContext;
import com.epam.player.vkapi.common.APIConstant;
import com.epam.player.vkapi.exceptions.CredentialsWrongException;
import com.epam.player.vkapi.exceptions.TemporarilyUnavailableServiceException;
import com.epam.player.vkapi.model.ApplContextTypes;

public class Authentication {

	private static final Logger LOG = Logger.getLogger(Authentication.class);

	ConnectionManager connectionManager;

	public Authentication() {
		connectionManager = new ConnectionManager();
	}

	public void loginToVK(String email, String pass)
			throws CredentialsWrongException,
			TemporarilyUnavailableServiceException {
		Map<String, String> data = new HashMap<String, String>();
		data.put(APIConstant.EMAIL, email);
		data.put(APIConstant.PASS, pass);
		LOG.info("User " + email + " loginning...");
		Connection connection = connectionManager.createConnection(data);
		LOG.info("Add  ApplContextTypes.CONNECTION  to ApllicationContext");
		ApllicationContext
				.addToContext(ApplContextTypes.CONNECTION, connection);

	}
}
